package com.example.qx.lei;

import android.content.ContentValues;
import android.content.Context;
import android.net.Uri;
import android.os.Environment;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.tencent.cos.xml.CosXmlService;
import com.tencent.cos.xml.CosXmlServiceConfig;
import com.tencent.cos.xml.exception.CosXmlClientException;
import com.tencent.cos.xml.exception.CosXmlServiceException;
import com.tencent.cos.xml.listener.CosXmlProgressListener;
import com.tencent.cos.xml.listener.CosXmlResultListener;
import com.tencent.cos.xml.model.CosXmlRequest;
import com.tencent.cos.xml.model.CosXmlResult;
import com.tencent.cos.xml.model.object.DeleteObjectRequest;
import com.tencent.cos.xml.model.object.GetObjectACLRequest;
import com.tencent.cos.xml.model.object.GetObjectRequest;
import com.tencent.cos.xml.model.tag.InitiateMultipartUpload;
import com.tencent.cos.xml.transfer.COSDownloadTask;
import com.tencent.cos.xml.transfer.COSXMLDownloadTask;
import com.tencent.cos.xml.transfer.COSXMLUploadTask;
import com.tencent.cos.xml.transfer.InitMultipleUploadListener;
import com.tencent.cos.xml.transfer.TransferConfig;
import com.tencent.cos.xml.transfer.TransferManager;
import com.tencent.cos.xml.transfer.TransferState;
import com.tencent.cos.xml.transfer.TransferStateListener;
import com.tencent.qcloud.core.auth.QCloudCredentialProvider;
import com.tencent.qcloud.core.auth.ShortTimeCredentialProvider;

import java.io.File;
import java.lang.reflect.Field;
import java.sql.Connection;

public class cos extends AppCompatActivity {

private  CosXmlService cosXmlService;
private CosXmlServiceConfig serviceConfig;
private QCloudCredentialProvider credentialProvider;

   public cos(){

      credentialProvider =new ShortTimeCredentialProvider("AKIDCg8Rev66znV4Wp13ALdrBiNCxdTROHHC", "BWsBRejvLtOqEVjv7DLKC1jcebN2e9Xm",300);
     serviceConfig =new CosXmlServiceConfig.Builder()
              .setRegion("ap-beijing")
              .isHttps(true)
              .builder();

   }
   public void insert(Uri uri, String a,Context context){
       cosXmlService =new CosXmlService(context,serviceConfig,credentialProvider);
      TransferConfig transferConfig =new TransferConfig.Builder()
              .setForceSimpleUpload(true)
              .build();
      TransferManager transferManager =new TransferManager(cosXmlService,transferConfig);
      COSXMLUploadTask cosxmlUploadTask=transferManager.upload("youqishuju-1327456541",a,uri,null);

}
  public void get(String a,Context context){
      cosXmlService =new CosXmlService(context,serviceConfig,credentialProvider);
      File file=context.getDir("youqishuju",context.MODE_PRIVATE);
      if(!file.exists())
          file.mkdirs();
      String loaclpath= file.getAbsolutePath();
      GetObjectRequest getObjectRequest=new GetObjectRequest("youqishuju-1327456541",a,loaclpath);
      cosXmlService.getObjectAsync(getObjectRequest, new CosXmlResultListener() {
          @Override
          public void onSuccess(CosXmlRequest cosXmlRequest, CosXmlResult cosXmlResult) {

          }

          @Override
          public void onFail(CosXmlRequest cosXmlRequest, @Nullable CosXmlClientException e, @Nullable CosXmlServiceException e1) {

          }
      });

    //return  Uri.parse(loaclpath+"/"+a);
   }
  public void delete (String a,Context context){
      cosXmlService =new CosXmlService(context,serviceConfig,credentialProvider);
      DeleteObjectRequest deleteObjectRequest =new DeleteObjectRequest("youqishuju-1327456541",a);
        cosXmlService.deleteObjectAsync(deleteObjectRequest, new CosXmlResultListener() {
            @Override
            public void onSuccess(CosXmlRequest cosXmlRequest, CosXmlResult cosXmlResult) {

            }

            @Override
            public void onFail(CosXmlRequest cosXmlRequest, @Nullable CosXmlClientException e, @Nullable CosXmlServiceException e1) {

            }
        });
  }
}
